<!--
 入参：
 sourcetype： 来源类型
 sourceid： 来源id
 relationcode： 检查项类别
 disableEditSubmit： 不可编辑
-->
<template>
  <div style="position: relative;">
    <div class="tl-form-line-title" style="display: block; float: left">
      检查项
    </div>
    <el-button icon="el-icon-document-checked" type="text" v-if="!disableEditSubmit" style="position: absolute; top: 7px; right: 15px" @click="tempSave" :loading="saveLoading">暂存</el-button>
    <div style="padding-left:15px;">
      <el-table ref="mainTable" class="tl-table" v-loading="loading" :data="datas" border fit>
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="checkname" label="名称" width="150px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="introduce" label="检查项内容" min-width="350px" sortable="custom" sort-by="introduce" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="检查结果" width="150px" sortable="custom" sort-by="introduce" align="center" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-select v-model="scope.row.result" filterable :disabled="disableEditSubmit">
              <el-option v-for="item in codeModel.resultList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="备注" width="350px" align="left" header-align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.description" :disabled="disableEditSubmit"></el-input>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { mixin_approval } from '@tapui/mixins/mixin_approval'
/** 子组件 */
/** 工具类 */
import { getAction, putAction } from '@tapui/utils/http'

/** VUE配置 */
export default {
  mixins: [mixin_list, mixin_approval],
  components: {},
  data() {
    return {
      moduleTitle: '检查项',
      urlPrefix: '/base/flowCheckItem/',
      url: {
        // 额外的url
        queryCheckItemIns: '/base/currencyCheckItemIns/queryList',
        queryCodeList: '/base/currencyCheckItemIns/dataCodeList',
        add: '/base/currencyCheckItemIns/add'
      },
      isQueryOnCreated: false,
      model: {},
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 0, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      tableHeight: 0,
      saveLoading: false
    }
  },
  props: {
    // 来源类型
    sourcetype: {
      default: '',
      type: String
    },
    // 来源id
    sourceid: {
      default: 0,
      type: Number
    },
    // 检查项类别
    relationcode: {
      default: '',
      type: String
    },
    // 不可编辑
    disableEditSubmit: {
      default: false,
      type: Boolean
    }
  },
  methods: {
    close() {},
    open() {
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = {
        sourcetype: this.sourcetype,
        sourceid: this.sourceid,
        relationcode: this.relationcode
      }
      // 数据查询
      this.loading = true
      getAction(this.url.queryCheckItemIns, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    tempSave() {
      if (!this.visible) {
        return
      }
      let paraMap = {
        datas: this.datas,
        sourcetype: this.sourcetype,
        sourceid: this.sourceid,
        relationcode: this.relationcode
      }
      this.loading = true
      putAction(this.url.add, paraMap).then((res) => {
        this.loading = false
        if (res.success) {
          this.$tap.message(res.message, 'success')
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    }
  },
  mounted() {
    this.loadData()
  }
}
</script>
<style scoped></style>
